package com.yf.controller.admin;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import com.yf.entity.CategoryGoodsEntity;
import com.yf.service.CategoryGoodsService;
import com.yf.response.R;
import com.yf.consts.DaoConst;


/**
 * 分类商品Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Thu Aug 16 13:36:44 CST 2018
 */
@RestController
@RequestMapping("/categorygoods")
public class CategoryGoodsController {
    @Autowired
    private CategoryGoodsService categoryGoodsService;

    /**
     * 列表分类商品
     */
    @RequestMapping("/list")
    @RequiresPermissions("categorygoods:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<CategoryGoodsEntity> categoryGoodsList = categoryGoodsService.queryList(params);
        return R.ok(new PageInfo(categoryGoodsList));
    }

    /**
     * 查看分类商品
     */
    @SysLog("查看分类商品")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("categorygoods:info")
    public R info(@PathVariable("id") Long id) {
        CategoryGoodsEntity categoryGoods = categoryGoodsService.get(id);

        return R.ok(categoryGoods);
    }

    /**
     * 保存分类商品
     */
    @SysLog("保存分类商品")
    @RequestMapping("/save")
    @RequiresPermissions("categorygoods:save")
    public R save(CategoryGoodsEntity categoryGoods) {
        categoryGoodsService.save(categoryGoods);

        return R.ok(categoryGoods);
    }

    /**
     * 修改分类商品
     */
    @SysLog("修改分类商品")
    @RequestMapping("/update")
    @RequiresPermissions("categorygoods:update")
    public R update(CategoryGoodsEntity categoryGoods) {
        categoryGoodsService.update(categoryGoods);

        return R.ok(categoryGoods);
    }

    /**
     * 删除分类商品
     */
    @SysLog("删除分类商品")
    @RequestMapping("/delete")
    @RequiresPermissions("categorygoods:delete")
    public R delete(@RequestBody Long[]ids) {
        categoryGoodsService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有分类商品
     */
    @SysLog("所有分类商品")
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<CategoryGoodsEntity> categoryGoodsList = categoryGoodsService.queryList(params);

        return R.ok(categoryGoodsList);
    }

    /***********自定义开始***********/
}
